<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>首页</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layuiMini/lib/layui-v2.6.6/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiMini/lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="/layuiMini/css/public.css" media="all">
    <style>
        .layui-card {border:1px solid #f2f2f2;border-radius:5px;}
        .icon {margin-right:10px;color:#1aa094;}
        .icon-cray {margin-right:10px;color:#ffb800!important;}
        .icon-blue {margin-right:10px;color:#1e9fff!important;}
        .icon-tip {margin-right:10px;color:#ff5722!important;}
        .layuimini-qiuck-module {text-align:center;margin-top: 10px}
        .layuimini-qiuck-module a i {display:inline-block;width:100%;height:60px;line-height:60px;text-align:center;border-radius:2px;font-size:30px;background-color:#F8F8F8;color:#333;transition:all .3s;-webkit-transition:all .3s;}
        .layuimini-qiuck-module a cite {position:relative;top:2px;display:block;color:#666;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;font-size:14px;}
        .welcome-module {width:100%;height:400px;}
        .panel {background-color:#fff;border:1px solid transparent;border-radius:3px;-webkit-box-shadow:0 1px 1px rgba(0,0,0,.05);box-shadow:0 1px 1px rgba(0,0,0,.05)}
        .panel-body {padding:10px}
        .panel-title {margin-top:0;margin-bottom:0;font-size:12px;color:inherit}
        .label {display:inline;padding:.2em .6em .3em;font-size:75%;font-weight:700;line-height:1;color:#fff;text-align:center;white-space:nowrap;vertical-align:baseline;border-radius:.25em;margin-top: .3em;}
        .layui-red {color:red}
        .main_btn > p {height:40px;}
        .layui-bg-number {background-color:#F8F8F8;}
        .layuimini-notice:hover {background:#f6f6f6;}
        .layuimini-notice {padding:7px 16px;clear:both;font-size:12px !important;cursor:pointer;position:relative;transition:background 0.2s ease-in-out;}
        .layuimini-notice-item { white-space: nowrap;line-height:20px}
        .layuimini-notice-title,.layuimini-notice-label {
            box-sizing: border-box;display: inline-block; padding-right: 10px;text-overflow:ellipsis;overflow:hidden;white-space:nowrap;}
        .layuimini-notice-title {line-height:28px;font-size:14px;padding: 7px 0px;}
        .layuimini-notice-extra {position:absolute;top:50%;margin-top:-8px;right:16px;display:inline-block;height:16px;color:#999;}
        /*select下拉框部分样式修改*/
        .layui-form-select dl dd.layui-this {
            background-color: #1E9FFF;!important;
            color: #fff;
        }
        .notCount{
            color: red;
            font-size: 20px
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main" style="height: 100%">
        <!--style="display: flex;"-->
        <div class="layui-row layui-col-space15" >
            <!--style="flex: 2.5;"-->
            <div class="layui-col-md9" >
                <div class="layui-row layui-col-space15">
                    <div class="layui-col-md6" style="min-height: 280px;">
                        <div class="layui-card">
                            <div class="layui-card-header"><i class="fa fa-pie-chart icon-blue"></i>整改概况</div>
                            <div class="layui-card-body">
                                <div class="welcome-module" id="solveCondition"></div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <div class="layui-card">
                            <div class="layui-card-header"><i class="fa fa-sliders icon-blue"></i>类型分布</div>
                            <div class="layui-card-body">
                                <div class="welcome-module" id="typeCondition"></div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-col-md12">
                        <div class="layui-card">
                            <div class="layui-card-header"><i class="fa fa-line-chart icon-blue"></i>
                                报表统计
                                <div class="layui-form layui-form-pane" style="margin-left: 15px;margin-top: 5px;float:right">
                                    <div class="layui-inline">
                                        <div class="layui-inline">
                                            <div class="layui-input-inline layui-show-xs-block" style="width: 130px;height: 50px">
                                                <select name="areaSelect" lay-search="" id="areaSelect" lay-filter="areaSelect">
                                                    <option value="">请选择区域</option>
                                                    <option value="底盘">底盘区域</option>
                                                    <option value="内饰">内饰区域</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-card-body">
                                <div id="peopleChartsInfo" style="width: 100%;min-height:400px"></div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!--style="flex: 1; display: flex; flex-direction: column;"-->
            <div class="layui-col-md3" >
                <!--style="height: 50%; box-sizing: border-box;"-->
                <div class="layui-card">
                    <div class="layui-card-header"><i class="fa fa-bullhorn icon icon-tip"></i>待办任务<span class="notCount" id="notDoCount"></span>项
                        <div style="float: right">
                            <a href="javascript:;" layuimini-content-href="/processManage/myNotDoPage" data-title="我的待办" data-icon="fa fa-dot-circle-o">
                                <i class="fa fa-search-plus icon icon-blue"></i>查看更多
                            </a>
                        </div>
                    </div>
                    <div class="layui-card-body layui-text" style="min-height: 400px;">
                        <div style="overflow: auto">
                            <table class="layui-text" style="min-width: 100%">
                                <tbody id="notDoInfo"></tbody>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="layui-card" >
                    <div class="layui-card-header"><i class="fa fa-folder-open icon-blue"></i>模板下载</div>
                    <div class="layui-card-body layui-text" >
                        <div id="attendanceChart1" style="height: 400px">
                            <div style="overflow: auto">
                                <table class="layui-text" style="min-width: 100%">
                                    <tbody id="fileTable"></tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="/layuiMini/lib/layui-v2.6.6/layui.js" charset="utf-8"></script>
<script src="/layuiMini/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="/module/js/echarts.min.js" charset="utf-8"></script>
<script src="/module/js/wonderland.js" charset="utf-8"></script>
<!--其自带的echarts.js没有工具栏模块-->
<script>
    var totalData;
    var dayData;
    var nightData;
    layui.use(['layer', 'miniTab','form','laydate'], function () {
        var $ = layui.jquery,
            layer = layui.layer,
            form = layui.form,
            laydate = layui.laydate,
            miniTab = layui.miniTab;
        miniTab.listen();

        //部门下拉框事件
        form.on('select(departmentAction)',function (data){
            var departmentChecked = $("#department").val();
            let factoryNumber;
            $.each(departmentList,function(index,value){
                if(value.department == departmentChecked){
                    factoryNumber = value.departmentNumber;
                }
            })
            if($("#department").val() != ""){
                $.ajax({
                    url:"/userManage/getFactoryInfo",
                    type:"GET",
                    data:{
                        factoryNumber : factoryNumber
                    },
                    dataType: "JSON",
                    success:function (res){
                        $('#office').find("option").remove();
                        $('#office').append(new Option("请选择科室",""))
                        if(res.respCode == "0000"){
                            $.each(res.data.office, function (index, value) {
                                $('#office').append(new Option(value.office,value.departmentNumber));// 下拉菜单里添加元素
                            });
                            layui.form.render("select");
                        }else{
                            $('#office').find("option").remove();
                            $('#office').append(new Option("请选择科室",""))
                            layui.form.render("select");
                        }
                    }
                })
            }else{
                $('#office').find("option").remove();
                $('#office').append(new Option("请选择科室",""))
                getSearchOffice()
                layui.form.render("select");
            }
        })

        // 基于准备好的dom，初始化echarts实例
        var solveChart = echarts.init(document.getElementById('solveCondition'),'wonderland');
        var solveOption = {
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            label: {
                show: true,
                position: 'inside',
                fontWeight: 'bold',
                fontFamily: 'Microsoft Yahei',
                fontSize: 14,
                formatter: '{b} : {c}'
            },
            legend: {
                orient: 'vertical',
                left: 'left',
            },
            toolbox: {
                feature: {
                    saveAsImage: {},
                    dataView: {},
                }
            },
            series: [
                {
                    name: '问题数量',
                    type: 'pie',
                    radius: '75%',
                    center: ['50%', '50%'],
                    formatter:"{a} <br/>{b} : {c} ({d}%)",
                    itemStyle: {
                        emphasis: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ]
        };
        solveChart.setOption(solveOption);
        solveChart.showLoading();    //数据加载完之前先显示一段简单的loading动画
        getAllProblemChart(solveChart);

        /**
         * 获取所有问题分为已整改和未整改
         */
        function getAllProblemChart(solveChart){
            var names = []
            $.ajax({
                url:'/problemManage/getSolveChartData?chartType=1',
                type: 'GET',
                dataType: 'json',
                success: function(res){
                    if (res.respCode == "0000") {
                        var allBoardChartData = new Array();
                        for(var i=0;i<res.data.data.length;i++){
                            var allBoardChartItems = new Object();
                            names.push(res.data.data[i].status);
                            allBoardChartItems.name = res.data.data[i].status;
                            allBoardChartItems.value = res.data.data[i].begin;
                            allBoardChartData.push(allBoardChartItems);
                        }
                        solveChart.hideLoading();
                        solveChart.setOption({
                            legend: {
                                data : names
                            },
                            series: [{
                                data: allBoardChartData
                            }]
                        });
                    } else {
                        solveChart.hideLoading();
                        layer.msg(res.data.msg, {icon: 5});
                    }
                }
            })
        }

        // 基于准备好的dom，初始化echarts实例
        var typeChart = echarts.init(document.getElementById('typeCondition'),'wonderland');
        var typeOption = {
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            label: {
                show: true,
                position: 'inside',
                fontWeight: 'bold',
                fontFamily: 'Microsoft Yahei',
                fontSize: 14,
                formatter: '{b} : {c}'
            },
            legend: {
                orient: 'vertical',
                left: 'left',
            },
            toolbox: {
                feature: {
                    saveAsImage: {},
                    dataView: {},
                }
            },
            series: [
                {
                    name: '问题数量',
                    type: 'pie',
                    radius: '75%',
                    center: ['50%', '50%'],
                    formatter:"{a} <br/>{b} : {c} ({d}%)",
                    itemStyle: {
                        emphasis: {
                            shadowBlur: 10,
                            shadowOffsetX: 0,
                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                        }
                    }
                }
            ]
        };
        typeChart.setOption(typeOption);
        typeChart.showLoading();    //数据加载完之前先显示一段简单的loading动画
        getTypeProblemChart(typeChart);

        /**
         * 获取所有问题分为已整改和未整改
         */
        function getTypeProblemChart(typeChart){
            console.log(123);
            var names = []
            $.ajax({
                url:'/problemManage/getSolveChartData?chartType=2',
                type: 'GET',
                dataType: 'json',
                success: function(res){
                    if (res.respCode == "0000") {
                        var allBoardChartData = new Array();
                        for(var i=0;i<res.data.data.length;i++){
                            var allBoardChartItems = new Object();
                            names.push(res.data.data[i].problemStyle);
                            allBoardChartItems.name = res.data.data[i].problemStyle;
                            allBoardChartItems.value = res.data.data[i].begin;
                            allBoardChartData.push(allBoardChartItems);
                        }
                        typeChart.hideLoading();
                        typeChart.setOption({
                            legend: {
                                data : names
                            },
                            series: [{
                                data: allBoardChartData
                            }]
                        });
                    } else {
                        typeChart.hideLoading();
                        layer.msg(res.data.msg, {icon: 5});
                    }
                }
            })
        }

        /**
         * 立项申请待办表格数据渲染
         */
        $.ajax({
            url:'/processManage/getNotDoList',
            type:'GET',
            data:{
                page:1,
                limit:6,
            },
            dataType:'JSON',
            success:function(res){
                console.log(res)
                if(res.respCode == "0000"){
                    var tableStr = '';
                    for(let i = 0;i < res.data.data.length;i++){
                        tableStr += '<tr class="layuimini-notice function" id=' + res.data.data[i].trackId + '>';
                        tableStr += '<td class="layuimini-notice-title" style="width: 70%" id="processName">' + res.data.data[i].processName + '</td>';
                        tableStr += '<td class="layuimini-notice-title" style="width: 30%" id="processType">' + res.data.data[i].applyType + '</td>';
                        tableStr += '</tr>';
                    }
                    $("#notDoInfo").html(tableStr);
                    $("#notDoCount").html(res.data.count);
                }else{
                    $("#notDoCount").html(0);
                }
            }
        })

        /**
         * 行工具点击事件
         */
        $('body').on('click','.function',function (){
            var index = layer.open({
                title: '流程详情',
                type: 2,
                shade: 0.2,
                maxmin:true,
                shadeClose: false,//点击遮罩层关闭弹出层
                area: ['100%', '100%'],
                content: '/processManage/processDetailPage?trackId=' +  this.id + "&pageType=2",
            });
            $(window).on("resize", function () {
                layer.full(index);
            });
            return false;
        })

        /**
         * 模板下载
         */
        $.ajax({
            url:'getFileList',
            type:'GET',
            data:{
                page:1,
                limit:6,
            },
            dataType:'JSON',
            success:function(res){
                console.log(res)
                if(res.respCode == "0000"){
                    var tableStr = '';
                    for(let i = 0;i < res.data.data.length;i++){
                        tableStr += '<tr class="layuimini-notice download" id=' + res.data.data[i].fileAddress + '>';
                        tableStr += '<td class="layuimini-notice-title" style="width: 70%" id="processName">' + res.data.data[i].fileName + '</td>';
                        tableStr += '<td class="layuimini-notice-title" style="width: 30%" id="processType">' + res.data.data[i].createTime + '</td>';
                        tableStr += '</tr>';
                    }
                    $("#fileTable").html(tableStr);
                }
            }
        })

        /**
         * 行工具点击事件
         */
        $('body').on('click','.download',function (){
            $.ajax({
                url: 'downLoadAnnex',
                type: 'GET',
                data: {
                    fileAddress : this.id
                },
                success: function (res){
                    location.href = this.url
                }
            })
            return false;
        })

        var peopleCharts = echarts.init(document.getElementById('peopleChartsInfo'),'wonderland');
        var peopleOption = {
            tooltip: {
                trigger: 'axis',
                axisPointer: {
                    type: 'cross',
                    crossStyle: {
                        color: '#999'
                    }
                }
            },
            legend:{
                // data: ['待整改','整改中','已整改']
            },
            toolbox: {
                feature: {
                    mark: {show: true},
                    dataView: {show: true, readOnly: true},
                    magicType: {show: true, type: ['line', 'bar',]},//层叠样式'stack'
                    saveAsImage: {show: true}
                },
                orient: "vertical"
            },
            xAxis: [
                {
                    type: 'category',
                    axisLabel:{
                        interval:0,
                        rotate:45,
                    }
                }
            ],
            yAxis: [
                {
                    type: 'value',
                    name: '数量',
                    min: 0,
                    max: 100,
                    interval: 20,
                    axisLabel: {
                        formatter: '{value} 个'
                    }
                },
                // {
                //     type: 'value',
                //     name: '出勤率',
                //     min: 0,
                //     max: 100,
                //     interval: 20,
                //     axisLabel: {
                //         formatter: '{value} %'
                //     }
                // }
            ],
            series: [
                {
                    name: '待整改',
                    type: 'bar',
                    stack: 'total',
                    label: {
                        show: true
                    },
                    emphasis: {
                        focus: 'series'
                    },
                },
                {
                    name: '整改中',
                    type: 'bar',
                    stack: 'total',
                    label: {
                        show: true
                    },
                    emphasis: {
                        focus: 'series'
                    },
                },
                {
                    name: '已整改',
                    type: 'bar',
                    stack: 'total',//叠加
                    label: {
                        show: true
                    },
                    emphasis: {//高亮
                        focus: 'series'
                    },
                }
            ]
        };
        peopleCharts.setOption(peopleOption);
        peopleCharts.showLoading();
        getPeopleData(peopleCharts);

        form.on('select(areaSelect)',function (data){
            console.log(data.value)
            getPeopleData(peopleCharts,data.value)
        })

        /**
         * 获取人员分类表格
         */
        function getPeopleData(echartsId,searchInfo){
            let name = [];
            let notDo = [];
            let doing = [];
            let done = [];
            $.ajax({
                url:"/problemManage/getPeopleChartsData",
                type:"GET",
                data:{
                    searchInfo : searchInfo
                },
                dataType:"JSON",
                success:function (res){
                    if(res.respCode == "0000"){
                        totalData = res.data.data;
                        console.log(totalData);
                        $.each(totalData,function (index,item){
                            name.push(item.managerName);
                            notDo.push(item.page);
                            doing.push(item.pmId);
                            done.push(item.begin);
                        })
                        echartsId.hideLoading();
                        echartsId.setOption({
                            xAxis: [
                                {
                                    data: name,
                                }
                            ],
                            series: [
                                {
                                    data: notDo,
                                },
                                {
                                    data: doing,
                                },
                                {
                                    data: done,
                                },
                            ]
                        })
                    }else{
                        echartsId.hideLoading();
                        layer.msg("查询结果为空",{icon:5});
                    }
                }
            })
        }

        // echarts 窗口缩放自适应
        window.onresize = function(){
            solveChart.resize();
            typeChart.resize();
            peopleCharts.resize();
        }
    });
</script>
</body>
</html>
